
var download_obj = null;
var msg_obj = null;
var simpleFile_obj = null;
var parameters_obj = null;

var m_waeErrorHandler = null;
var m_returnCallback = null;


function openMessage(msg){
	m_returnCallback=null;
	if(arguments.length>1&&arguments[1])
		m_returnCallback = arguments[1];
		
	// if(!msg){
			// alert("==提示信息为空，请联系管理员！==")
			// return;
		// }
		// var _errorcode = m_tipsJson[msg];
		// if(!_errorcode){
			// alert("==未找到相应的错误代码，请联系管理员！==");
			// return;
		// }
		// m_waeErrorHandler.noticeErrorCode(_errorcode);

	alert(msg);
}



window.onWAEReady = function (){
	
	
	if(wae.can("tools.ErrorHandler")&&wae.can("tools.ErrorHandler")==true){
		m_waeErrorHandler = wae.create("tools.ErrorHandler");
	}
	
		//弹出框返回处理函数
	m_waeErrorHandler.onErrorHandlerResult = function(e){
		var _returnCode = e.arguments[0];
		if(_returnCode==0)
			return;
			
		if(m_returnCallback)
				eval("("+m_returnCallback+")");
	}
	
		download_obj = wae.create("Net.Downloader");
		
		msg_obj = wae.create("Toast");
		simpleFile_obj = wae.create("DATA.SimpleFile");
		parameters_obj = wae.create("DATA.Parameters");
		eventSender_obj = wae.create("EventSender");
		
		var focusid =  waeparams.getPersistence("OLDID");
		if(focusid == ''||!focusid){
			focusid = 0;
		}
		eventSender_obj.focus(document.getElementById("main").getElementsByTagName("input")[focusid].offsetLeft, document.getElementById("main").getElementsByTagName("input")[focusid].offsetTop);	
		
		showVersion();
		VatataPublic.updatetime_Temperature($("weekId"),$("timeId"),$("temperatureId"),$("temperatureImgId"));
	
}

function changeBg(imgurl,id){

		var url = imgurl+'images/bj/'+id+'.png';
		
		msg_obj = wae.create("Toast");
		
		msg_obj.showMessageWithShortDuration('正在将此图设为壁纸，请稍等。。。');
		
		waeparams.addPersistence("OLDID", id);
		
		download_obj.downloadToSharedInnerFlash(url);
		download_obj.onSuccess = function(e) {
			var argument0 = e.arguments[0].toLocaleString(); //下载文件的URL
			var argument1 = e.arguments[1].toLocaleString(); //下载文件的save 地址
			var new_bg_css = 'body{background:url('+argument1+') repeat-y;background-size:1280px 720px;}';
			simpleFile_obj.writeToRootPath("bgimg.css", new_bg_css, true);
			
			msg_obj.showMessageWithLongDuration('成功将此图设为壁纸！');
		}
		download_obj.onFailure = function(e) {
			var argument0 = e.arguments[0].toLocaleString(); //下载文件的URL
			var argument1 = e.arguments[1].toLocaleString(); //下载文件的save 地址
			msg_obj.showMessageWithLongDuration('失败！请重试！');
		}
	
}


var focusid = false;
function setbgimg(id){
	
	
	if(focusid ==false){
		focusid = true;
	}else{
		var imgurl = location.href.replace(/wallpaper.html/g,'');
	
		var msg = "您想将此图片设为背景图片吗？";		
		// var _fun = "changeBg('"+imgurl+"',"+id+")";
		// openMessage(msg,_fun);

		
		if(window.confirm(msg)){
			changeBg(imgurl,id);
		}
	}
}
